radix64
Fast and easy base64 encoding and decoding.
Usage
Encode and decode with the standard alphabet
use STD;
let encoded = STD.encode;
let decoded = STD.decode.unwrap;
assert_eq!;
Encode and decode with the url safe alphabet
use URL_SAFE;
let encoded = URL_SAFE.encode;
let decoded = URL_SAFE.decode.unwrap;
assert_eq!;
Encode multiple messages reusing the same allocated buffer for each message.
use STD;
let mut buf = Vec new;
let encoded = STD.encode_with_buffer;
let encoded = STD.encode_with_buffer;
Decode multiple messages reusing the same allocated buffer for each message.
use STD;
let mut buf = Vec new;
let decoded = STD.decode_with_buffer;
let decoded = STD.decode_with_buffer;
Define and use a custom alphabet
use ConfigBuilder;
let my_cfg =
with_alphabet
.no_padding
.build
.unwrap;
let encoded = my_cfg.encode;
let decoded = my_cfg.decode.unwrap;
Performance
The standard alphabets (STD, URL_SAFE, and CRYPT) along with the NO_PAD variants all have an AVX2 optimized encoder and decoder. This provides a huge performance boost if running on an AVX2 enabled CPU. A runtime check will be performed by default to see if AVX2 is available. If you specify compiling for an AVX2 enabled platform the runtime check will be avoided. If you want to avoid using the AVX2 implementation you can disable the "simd" feature when compiling the crate.
See a sample of benchmark runs here